package com.itheima.controller.backend;

import com.itheima.common.constant.MessageConstant;
import com.itheima.common.entity.Result;
import com.itheima.pojo.vo.BusinessReportData;
import com.itheima.service.ReportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/report")
public class ReportController {
    @Autowired
    private ReportService reportService;

    /**
     * 会员数量统计
     * @return
     */
    @GetMapping("/getMemberReport")
    public Result getMemberReport(){
        Map<String, List<String>> report = reportService.getMemberReport();
        if(null != report){
            return new Result(true, MessageConstant.GET_MEMBER_NUMBER_REPORT_SUCCESS, report);
        }else{
            return new Result(false, MessageConstant.GET_MEMBER_NUMBER_REPORT_FAIL);
        }
    }

    /**
     * 套餐预约占比统计
     * @return
     */
    @GetMapping("/getSetmealReport")
    public Result getSetmealReport(){
        Map<String, Object> report = reportService.getSetmealReport();
        if(null != report){
            return new Result(true, MessageConstant.GET_SETMEAL_COUNT_REPORT_SUCCESS, report);
        }else{
            return new Result(false, MessageConstant.GET_SETMEAL_COUNT_REPORT_FAIL);
        }
    }

    /**
     * 运营数据统计
     * @return
     */
    @GetMapping("/getBusinessReportData")
    public Result getBusinessReportData(){
        BusinessReportData brd = reportService.getBusinessReportData();
        if(null != brd){
            return new Result(true, MessageConstant.GET_BUSINESS_REPORT_SUCCESS, brd);
        }else{
            return new Result(false, MessageConstant.GET_BUSINESS_REPORT_FAIL);
        }
    }

    /**
     * 导出运营数据统计
     * @param response
     * @return
     */
    @GetMapping("/exportBusinessReport")
    public Result exportBusinessReport(HttpServletResponse response){
        Boolean success = reportService.exportBusinessReportData(response);
        if(success){
            return new Result(true, "下载文件");
        }else{
            return new Result(false, "下载文件失败");
        }
    }
}
